﻿<script type="text/javascript">
    $(function () {
        getButton("bug");
        
    });
    function ui_bug_init_list(toolbar) {
        $("#ui_bug_dg").datagrid({       //初始化datagrid
            url: "ashx/rm_bug.ashx?action=search",
            striped: true, rownumbers: true, pagination: true, pageSize: 20,
            idField: 'id',
            sortName: 'bugDate',
            sortOrder: 'desc',
            pageList: [20, 40, 60, 80, 100],
            frozenColumns: [[
                { field: 'ck', checkbox: true },
                {
                    width: 100,
                    title: '报告人',
                    field: 'userName',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return value.length > 10 ? '<span title="' + value + '">' + value + '</span>' : value;
                    }
                }
            ]],
            columns: [[
                
                { field: 'userIp', title: 'IP地址', sortable: true, width: 100 },
                       {
                           field: 'bugInfo', title: '明细', width: 200,
                           formatter: function (value, row, index) {
                               return value.length > 50 ? '<span title="' + value + '">' + value + '</span>' : value;
                           }
                       }, {
                           field: 'bugReply', title: '回复内容', width: 200,
                           formatter: function (value, row, index) {
                               return value && value.length > 50 ? '<span title="' + value + '">' + value + '</span>' : value;
                           }
                       },
                       {
                           field: 'ifSolve', title: '是否解决', sortable: true, width: 80, align: 'center',
                           formatter: function (value, row, index) {
                               return value ? '<img src="../easyui/themes/icons/chk_checked.gif" alt="已解决" title="已解决" />' : '<img src="../easyui/themes/icons/chk_unchecked.gif" alt="未解决" title="未解决" />';
                           }
                       },
                       { field: 'bugDate', title: '报告时间', sortable: true, width: 130 }
            ]],
            toolbar: toolbar.length == 0 ? null : toolbar
            //toolbar: [{
            //    text: '导出',
            //    iconCls: 'icon-bug_go',
            //    handler: function () { ui_bug_export(); }
            //}, {
            //    text: '删除',
            //    iconCls: 'icon-bug_delete',
            //    handler: function () { ui_bug_delete(); }
            //}, {
            //    text: '回复',
            //    iconCls: 'icon-bug_edit',
            //    handler: function () { ui_bug_edit(); }
            //}]
        });
        //回车搜索
        $("#ui_bug_search").find('input').on('keyup', function (event) {
            if (event.keyCode == '13') {
                ui_bug_searchdata();
            }
        })
    }

    function ui_bug_export() {
        $.show_warning("提示", "Bug导出功能暂未实现");
    }
    function ui_bug_add() {        
        $("<div/>").dialog({
            id: "ui_bug_add_dialog",
            href: "html/ui_bug_edit.html",
            title: "报告问题",
            iconCls: 'icon-add',
            height: 350,
            width: 460,
            modal: true,
            buttons: [{
                id: "ui_bug_add_btn",
                iconCls: 'icon-add',
                text: '提交',
                handler: function () {
                    $("#ui_bug_editform").form("submit", {
                        url: "ashx/rm_bug.ashx",
                        onSubmit: function (param) {
                            $('#ui_bug_add_btn').linkbutton('disable');   //点击就禁用按钮，防止连击
                            param.action = 'add';
                            if ($(this).form('validate'))
                                return true;
                            else {
                                $('#ui_bug_edit_btn').linkbutton('enable');   //恢复按钮
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = eval('(' + data + ')');    //转成json格式
                            if (dataJson.success) {
                                $("#ui_bug_add_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", "添加成功！");
                                $("#ui_bug_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_bug_add_btn').linkbutton('enable');    //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $("#ui_bug_reply_edit").attr("disabled", "disabled");
                $("#ui_bug_ifsolve_edit").attr("disabled", "disabled");
            },
            onClose: function () {
                $("#ui_bug_add_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }
    function ui_bug_edit() {
        var rows = $("#ui_bug_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请先勾选要修改的用户或者双击某个Bug");
            return;
        }
        if (rows.length > 1) {
            $.show_warning("提示", "不支持批量回复");
            $("#ui_bug_dg").datagrid('clearSelections').datagrid('clearChecked');
            return;
        }
        var row = rows[0];
        $("<div/>").dialog({
            id: "ui_bug_edit_dialog",
            href: "html/ui_bug_edit.html",
            title: "问题回复",
            iconCls: 'icon-edit',
            height: 350,
            width: 460,
            modal: true,
            buttons: [{
                id: "ui_bug_edit_btn",
                iconCls: 'icon-edit',
                text: '回复',
                handler: function () {
                    $("#ui_bug_editform").form("submit", {
                        url: "ashx/rm_bug.ashx",
                        onSubmit: function (param) {
                            $('#ui_bug_edit_btn').linkbutton('disable');   //点击就禁用按钮，防止连击
                            param.action = 'reply';
                            if ($(this).form('validate'))
                                return true;
                            else {
                                $('#ui_bug_edit_btn').linkbutton('enable');   //恢复按钮
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = eval('(' + data + ')');    //转成json格式
                            if (dataJson.success) {
                                $("#ui_bug_edit_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", "回复成功！");
                                $("#ui_bug_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_bug_edit_btn').linkbutton('enable');    //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $("#ui_bug_id_edit").val(row.id);
                $("#ui_bug_username_edit").textbox("setValue", row.userName);
                $("#ui_bug_buginfo_edit").val(row.bugInfo);
                $("#ui_bug_reply_edit").val(row.bugReply);
                if (row.ifSolve) {
                    $("#ui_bug_ifsolve_edit").attr("checked", "checked");
                }                
            },
            onClose: function () {
                $("#ui_bug_edit_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }


    function ui_bug_delete() {
        var rows = $("#ui_bug_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请先勾选要删除的日志");
            return;
        }
        $.messager.confirm('提示', '确定删除勾选的这' + rows.length + '条日志？', function (r) {
            if (r) {
                para = {};
                para.action = "delete";
                para.timespan = new Date().getTime();

                var ids = [];
                $.each(rows, function (i, row) {
                    ids.push(row.id);
                });
                para.ids = ids.join(",");
                $.ajax({
                    url: "ashx/rm_bug.ashx",
                    data: para,
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        if (data.success) {
                            $.show_warning("提示", "删除成功！");
                            $("#ui_bug_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                        } else {
                            $.show_warning("提示", data.msg);
                        }
                    }
                });
            }
        });
    }
    function ui_bug_searchdata() {
        $("#ui_bug_dg").datagrid('load', {
            ui_bug_username: $('#ui_bug_search').find('[name=ui_bug_username]').val(),
            ui_bug_userip: $('#ui_bug_search').find('[name=ui_bug_userip]').val(),
            ui_bug_info: $('#ui_bug_search').find('[name=ui_bug_info]').val(),
            ui_bug_description: $('#ui_bug_search').find('[name=ui_bug_description]').val(),
            ui_bug_success: $('#ui_bug_search').find('[name=ui_bug_success]').val(),
            ui_bug_operatedatestart: $('#ui_bug_search').find('[name=ui_bug_operatedatestart]').val(),
            ui_bug_operatedateend: $('#ui_bug_search').find('[name=ui_bug_operatedateend]').val()
        });
        $("#ui_bug_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_bug_layout').layout('collapse', 'east');    //隐藏
    }
    function ui_bug_cleardata() {
        $('#ui_bug_search input').val('');
        $('#ui_bug_search select').val('select');
        $('#ui_bug_operatedatestart').datetimebox('setValue', '');
        $('#ui_bug_operatedateend').datetimebox('setValue', '');
        $("#ui_bug_dg").datagrid('load', {});

        $("#ui_bug_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_bug_layout').layout('collapse', 'east');    //隐藏
    }
</script>
<div id="ui_bug_layout" class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'east',split:true,border:true,collapsed:true" title="多条件过滤"
        style="width: 280px;">
        <div id="ui_bug_search">
            <table class="tableForm" style="width: 100%; height: 100%; background: #F5F5F5;">
                <tr>
                    <th>
                        操作人：
                    </th>
                    <td>
                        <input name="ui_bug_username" autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>
                        操作IP：
                    </th>
                    <td>
                        <input name="ui_bug_userip" autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>
                        操作：
                    </th>
                    <td>
                        <input name="ui_bug_info" autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>
                        操作明细：
                    </th>
                    <td>
                        <input name="ui_bug_description" autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>
                        操作成功：
                    </th>
                    <td>
                        <select name="ui_bug_success">
                            <option value="select">请选择</option>
                            <option value="true">是</option>
                            <option value="false">否</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>
                        操作时间：
                    </th>
                    <td>
                        <input name="ui_bug_operatedatestart" id="ui_bug_operatedatestart"
                            class="easyui-datetimebox" editable="false" style="width: 140px;" />
                    </td>
                </tr>
                <tr>
                    <th>
                        至：
                    </th>
                    <td>
                        <input name="ui_bug_operatedateend" id="ui_bug_operatedateend" class="easyui-datetimebox"
                            editable="false" style="width: 140px;" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                            onclick="ui_bug_searchdata();">搜索</a>
                    </td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                            onclick="ui_bug_cleardata();">清空条件</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div data-options="region:'center',border:false">
        <table id="ui_bug_dg" data-options="fit:true,border:false">
        </table>
    </div>
</div>
